package org.zpmis.api.http;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zpmis.api.business.ContractBillWebService;
import org.zpmis.common.base.BaseController;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.domain.contract.qo.AddContractBillQo;
import org.zpmis.domain.contract.qo.ConfirmReceiptQo;
import org.zpmis.domain.contract.qo.ContractBillListQo;

import javax.annotation.Resource;

/**
* created with CodeGenerator
* description: 合同账单处理接口
* @author  Yang
* date: 2021-6-2
* time: 14:52:19
*/
@RestController
@RequestMapping("/contract/bill")
@Slf4j
public class ContractBillController extends BaseController{

    @Resource
    private ContractBillWebService contractBillWebService;


    /**
     * 新增合同账单
     * @param addContractBillQo
     * @return
     */
    @PostMapping("/addContractBill")
    public PlatformResult addContractBill(@Validated @RequestBody AddContractBillQo addContractBillQo){
        try {
            contractBillWebService.addContract(addContractBillQo);
            return PlatformResult.success();
        } catch (BusinessException be) {
            log.error("[ContractBillController]---addContractBill--->BusinessException:",be);
            return PlatformResult.failure(be.getResultCode());
        } catch (Exception e) {
            log.error("[ContractBillController]---addContractBill--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 合同账单列表查询
     * @param contractBillListQo
     * @return
     */
    @PostMapping("/contractBillList")
    public PlatformResult contractBillList(@RequestBody ContractBillListQo contractBillListQo){
        try {
            return PlatformResult.success(contractBillWebService.contractBillList(contractBillListQo));
        } catch (BusinessException be) {
            log.error("[ContractBillController]---contractBillList--->BusinessException:",be);
            return PlatformResult.failure(be.getResultCode());
        } catch (Exception e) {
            log.error("[ContractBillController]---contractBillList--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 确认合同账单收款
     * @param confirmReceiptQo
     * @return
     */
    @PostMapping("/confirmReceipt")
    public PlatformResult confirmReceipt(@Validated @RequestBody ConfirmReceiptQo confirmReceiptQo){
        try {
            contractBillWebService.confirmReceipt(confirmReceiptQo);
            return PlatformResult.success();
        } catch (BusinessException be) {
            log.error("[ContractBillController]---confirmReceipt--->BusinessException:",be);
            return PlatformResult.failure(be.getResultCode());
        } catch (Exception e) {
            log.error("[ContractBillController]---confirmReceipt--->Exception:",e);
            return PlatformResult.failure();
        }
    }

}
